<?php
//Set up the system
require('config.include.php');
//Auth stuff
require('auth.include.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Manage Attachments</title>
<link rel="stylesheet" href="admin.css" />
</head>

<body>
<div id="wrapper">
	<div id="header">
    	<?php echo('<a href="../" class="breadcrumb">'.SITE_TITLE.'</a> &raquo; <a href="dashboard.php" class="breadcrumb">Dashboard</a> &raquo; <a href="attachments.php" class="breadcrumb">Manage Attachments</a>'); ?>
    </div>
    <div id="sidebar">
<?php
	require('nav.include.php');
?>
    </div>
    <div id="content">
        <div class="contentblock">
<?php
	echo('<h2>Manage Attachments</h2>');
	//Something to delete?
	if(isset($_GET['delete'])) {
		$delFile=fetch::unescapePostVar($_GET['delete']);
		if(isset($_GET['confirm'])) {
			if(!$_p->get_attachment($delFile,'../'.UPLOAD_PATH)) {
				echo('Error: Attachment "'.$delFile.'" could not be deleted.');
			}
			else {
				$_p->delete_attachment($delFile,'../'.UPLOAD_PATH);
				echo('Attachment deleted, remember to remove any dead links.<br /><br />');
			}
		}
		else {
			echo('Are you sure you want to delete the attachment "'.$delFile.'"?<br />
			<a href="attachments.php?delete='.htmlentities($delFile).'&amp;confirm">Yes</a> | <a href="attachments.php">Cancel</a><br /><br />');
		}
	}
	
	//Load the list
	$attachments=$_p->get_attachments('../'.UPLOAD_PATH);
	if(count($attachments)>0) {
		foreach($attachments as $attachment) {
			echo('<strong>'.$attachment.'</strong> ('.round(filesize('../'.UPLOAD_PATH.'/'.$attachment)/1000,1).'kb) <a href="attachments.php?delete='.htmlentities($attachment,ENT_QUOTES,'UTF-8').'">Delete</a><br />');
		}
	}
	else
		echo('<br />No attachments to display.');
?>
		</div>
    </div>
    <div id="footer">
    </div>
</div>
</body>
</html>